<template>
  <textarea
    v-model="markdownContent"
    @input="handelInput"
    placeholder="输入Markdown内容"
    maxlength="20000"
  ></textarea>
  <rich-text :nodes="compiledMarkdown" class="text"></rich-text>
</template>

<script>
import MarkdownIt from "markdown-it/dist/markdown-it.min.js";
import colorGradient from "uview-ui/libs/function/colorGradient";
const md = new MarkdownIt();
export default {
  name: "MarkdownIt",
  props: {
    content: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      markdownContent: "",
    };
  },
  methods: {
    handelInput() {
      this.$emit("input", this.markdownContent);
    },
  },
  computed: {
    compiledMarkdown() {
      return md.render(this.markdownContent);
    },
  },
  watch: {
    content(val) {
      this.markdownContent = val;
    },
  },
};
</script>

<style scoped>
/* 样式可根据需要调整 */
textarea {
  height: 200px;
  width: 100%;
  margin-bottom: 20px;
  overflow: scroll;
}

.text {
  display: block;
  height: 200px;
  width: 100%;
  overflow: scroll;
  border-top: 1px solid #ccc;
}
</style>
